﻿using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace GDI.Service
{
    [Description("Label с градиентной заливокой")]
    public partial class GradientLabel : Label
    {
        /* ------------------------------------------------------------------------------------------ */

        private Color f_StartColor = Color.LightGreen;

        private Color f_EndColor = Color.DarkBlue;

        /* ------------------------------------------------------------------------------------------ */

        [Category("Gradient"), DefaultValue(typeof(Color), "LightGreen")]
        [MergableProperty(true)] // Допустимо груповое изменение свойства
        [Browsable(true), DisplayName("Start color"), ReadOnly(false)]
        [ParenthesizePropertyName(true)] //Имя свойства в круглые скобки 
        public Color StartColor
        {
            get { return f_StartColor; }
            set
            {
                f_StartColor = value;
                Invalidate();
            }
        }

        [Category("Gradient"), DefaultValue(typeof(Color), "DarkBlue")]
        [MergableProperty(true)] // Допустимо груповое изменение свойства
        [Browsable(true), DisplayName("Stop color"), ReadOnly(false)]
        [ParenthesizePropertyName(true)] //Имя свойства в круглые скобки 
        public Color EndColor
        {
            get { return f_EndColor; }
            set
            {
                f_EndColor = value;
                Invalidate();
            }
        }

        /* ------------------------------------------------------------------------------------------ */

        public GradientLabel() { InitializeComponent(); }

        /* ------------------------------------------------------------------------------------------ */

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            var lv_StartColor = Color.FromArgb(100, f_StartColor);
            var lv_EndColor = Color.FromArgb(100, f_EndColor);

            using(var lv_Brush = new LinearGradientBrush(ClientRectangle, lv_StartColor, lv_EndColor, 10))
                e.Graphics.FillRectangle(lv_Brush, ClientRectangle);

        }

        /* ------------------------------------------------------------------------------------------ */
    }
}
